﻿using System.Security.Cryptography;
using System.Text;

namespace MasApp.BLL
{
    /// <summary>
    ///String 字符串操作
    /// </summary>
    public class StrHelper
    {
        public StrHelper()
        {
        }
        static StrHelper()
        {
            //静态初始化
        }

        /// <summary>
        /// md5哈希格式化字符串
        /// </summary>
        /// <param name="encodestr">str to be encode</param>
        /// <returns>encoded str</returns>
        public static string md5Encode(string encodestr)
        {
            if (encodestr == string.Empty)
            {
                return string.Empty;
            }
            byte[] bs = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(encodestr));
            StringBuilder sb = new StringBuilder(bs.Length);
            foreach (byte b in bs)
            {
                // 以十六进制格式格式化
                sb.Append(b.ToString("x"));
            }

            return sb.ToString();
        }
    }
}